package cn.lanqiao.system.service;

import cn.lanqiao.system.dao.UserMapper;
import cn.lanqiao.system.dao.UserRoleMapper;
import cn.lanqiao.system.entity.User;
import cn.lanqiao.system.vo.InsertOrUpdateUserVo;
import cn.lanqiao.system.vo.QueryUserVo;
import cn.lanqiao.system.vo.UserVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class UserService {

    @Autowired
    UserMapper userMapper;

    @Autowired
    UserRoleMapper userRoleMapper;

    @Transactional
    public void insertUser(InsertOrUpdateUserVo userVo){
        userMapper.insertUser(userVo);
        userRoleMapper.insert(userVo.getUserId(),userVo.getRoleId());
    }

    public User checkUser(User user) {
        return userMapper.checkUser(user);
    }

    public List<UserVo> getUserListByPage(QueryUserVo queryUserVo) {
        return userMapper.selectUserByPage(queryUserVo);
    }

    @Transactional
    public void deleteUser(int userId){
        userMapper.deleteByPrimaryKey(userId);
//        userRoleMapper.deleteById(userId);
    }


}
